//
//  DownViewController.m
//  LimitFree
//
//  Created by Hailong.wang on 15/8/26.
//  Copyright (c) 2015年 Hailong.wang. All rights reserved.
//

#import "DownViewController.h"
#import "LeftViewController.h"
#import "LoadingView.h"
@interface DownViewController ()
{
    //分类的ID
    NSString* _categoreID;
    //货币类型
    NSString* _currency;
    //分类页面
    LeftViewController *_lvc;
}
@end


@implementation DownViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //[LoadingView showLoadingView:self.view];
    self.title=@"降价";
    
    // Do any additional setup after loading the view.
}
-(void)initData{
    [LoadingView showLoadingView:self.view];
    _currency=@"rmb";
    _categoreID=@"0";
    //将页面设置为第一页
    self.page=1;
    //去拿网络数据
    [self getNetData];
}
-(void)createView{
    [super createView];
    
    _lvc = [LeftViewController shareSingleton];
}
//将分类展示的行为放在子视图控制器
-(void)toShowAppClassify{
    [_lvc showView:^(NSString* category){
        //NSLog(@"%@",category);
        
        //666 通过id 分类
        _categoreID=category;
        [self resetParame];
        [self getNetData];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//重置参数
-(void)resetParame{
    //将参数默认改为1，只拿第一页数据
    self.page=1;
    
}
//获取网络数据
-(void)getNetData{
    __weak typeof (self) weakSelf=self;
    [NetRequestManager GET:kReduceUrl parame:[NSDictionary dictionaryWithObjectsAndKeys:_currency,@"currency",[NSString stringWithFormat:@"%ld",self.page] ,@"page",_categoreID,@"category_id",nil] succes:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (self.page==1) {
            //整理数据
            weakSelf.data=[[ListModel alloc]initWithData:responseObject error:nil];
        }else{
            ListModel* temp=[[ListModel alloc]initWithData:responseObject error:nil];
            //加的是数组
            [weakSelf.data.applications addObjectsFromArray:temp.applications];
        }
        
        //刷新页面
        [weakSelf refreshView];
        
        [LoadingView hideLoadingView];
        
        // NSLog(@"%@ %@",operation.request ,responseObject);
    } failed:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */


@end
